<template>
  <div>
    <table>
      <tr>
        <td>标题</td>
        <td>操作</td>
      </tr>
      <tr v-for="i in list">
        <td>{{i.title}}</td>
        <td><button @click="add_btn(i.id)">评论</button><button @click="show_btn(i.id)">查看</button><button @click="btn">搜索</button></td>
      </tr>
    </table>
  </div>

</template>

<script>
    export default {
        name: "Shownews",
        data(){
          return{
            list:[],
          }
        },
        methods:{
          add_btn(id){
            if(sessionStorage.getItem('user_id')){
              this.$router.push('/AddComment/'+id)
            }else {
              alert('请先登录')
              this.$router.push('/Login')
            }
          },
          show_btn(id){
            this.$router.push('/Show/'+id)
          },
          btn(){
            this.$router.push('/Compare')
          }
        },
        created() {
          axios({
            url:'http://127.0.0.1:8000/app01/add_news/',
            method:'get'
          }).then(res=>{
            console.log(res)
            this.list=res.data
          })
        }
    }
</script>

<style scoped>

</style>